package com.sanjiahantang.youjiaclient.module.invoice.presenters;


import android.content.Context;

import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.youjiaclient.base.BaseBean;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.base.BaseMvpPresenter;
import com.sanjiahantang.youjiaclient.base.BaseView;
import com.sanjiahantang.youjiaclient.base.CallBack;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.module.invoice.views.InvoiceView;
import com.sanjiahantang.youjiaclient.module.me.order.models.IOrderModel;
import com.sanjiahantang.youjiaclient.module.me.order.models.impl.OrderModel;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/7/25.
 */

public class InvoicePresenter extends BaseMvpPresenter<InvoiceView> {

    private IOrderModel orderModel;
    public InvoicePresenter(){
        orderModel = new OrderModel();
    }

    public void saveInvoiceInfoPhoneForCustomer(final Context context,
                                                String isPersonalOrCompany,
                                                String invoiceTitle,
                                                String taxNum,
                                                String orderCode,
                                                float money,
                                                int typeId,
                                                final BaseView.OnLoadListener listener){
        Map<String,Object> param = new HashMap<>();
        param.put("isPersonalOrCompany",isPersonalOrCompany);
        param.put("orderCode",orderCode);
        param.put("invoiceTitle",invoiceTitle);
        param.put("taxNum",taxNum);
        param.put("money",money);
        param.put("typeId",typeId);
        param.put("phoneTypeId",0);
        param.put(KEY_TOKEN, ConfigValue.DATA_KEY);
        orderModel.saveInvoiceInfoPhoneForCustomer(context,param, new CallBack<BaseBean>() {
            @Override
            public void onSuccess(BaseBean response, Context context, Object tag) {
                if (mView == null)return;
                mView.hideProgress();
                if (response != null && response.getCode() == RESPONSE_CODE_SUC){
                    listener.onLoad(null);
                }else {
                    Utils.showToast(context,"保存发票信息失败");
                }
            }

            @Override
            public void onFailure(String message) {
                if (mView == null)return;
                mView.hideProgress();
                Utils.showToast(context,"保存发票信息失败");
            }
        });
    }
}
